module.exports = options => {
    return async function userToken (ctx,next) {
        const source = ctx.get('Authorization')
        if (!source) return ctx.body = { state:'err' }
        try {
            const token = ctx.app.jwt.verify(source,options.secret)
            const res = await ctx.model.User.findOne({ phone:token.phone,password:token.password })
            if (!res) return ctx.body = { state:'err',errMsg:'token过期' }
            ctx.user = res
            await next()
        } catch (e) {
            console.log(e)
            ctx.body = {
                state:'err'
            }
        }
    }
}
